﻿using System;
using EmbeddedSharp.Core;

namespace EmbeddedSharp.Scripting.Function.Profiling
{
    public class TimeDiffNode : FuncNode
    {
        public TimeDiffNode()
            : base("diff")
        {
        }

        public override object Evaluate()
        {
            int length = Parameters.Count;

            DateTime first 
                = Convert.ToDateTime(
                Parameters[length - 1].Evaluate());
            DateTime next 
                = Convert.ToDateTime(
                Parameters[length - 2].Evaluate());

            return next.Subtract(first).Milliseconds;
        }
    }
}
